/*
 * @Date: 2023-01-22 07:40:33
 * @LastEditors: 恶名扬 2080156129@qq.com
 * @LastEditTime: 2023-01-24 01:23:26
 * @FilePath: \campus-repair-platform\server\service\common\repair.js
 */

/**
 * getInfoRepair    获取报修单信息
 */
const repairStatement = require("../../common/sql_sentences/repair")

exports.getInfoRepair = async (req, res) => {
  try {
    const info = req.auth
    // 获取报修单信息
    const sqlStr = repairStatement.idSelect(req.params.id)
    let results = await RunSQL(sqlStr)
    if (results.length !== 1) return res.successSend("获取报修单信息失败！", 10005)
    if (!(info.type > 2 ||
      results[0].s_number === info.s_number || results[0].r_number === info.job_number
    )) return res.successSend("没有权限查看该报修单！", 10005)
    return res.successSend("", 10000, results[0])
  } catch (error) {
    res.errSend(error)
  }
}

exports.getStateCont = async (req, res) => {
  try {
    const info = req.auth
    const query = info.type < 3 ? info.type === 1 ? { s_number: info.s_number } : { r_number: info.job_number } : {}
    return res.successSend("", 10000, await RunSQL(repairStatement.selectGroup(query, req.auth.type)))
  } catch (error) {
    res.errSend(error)
  }
}
